<template>
  <div class="banners">
    <div class="banner" v-for="(item,index) in banners" :key="item.banner" >
      <img :src="item.banner" >
      <div class="banner-mask">
        <a-icon type="edit" @click.native="$emit('edit',item)"></a-icon>
        <a-icon type="delete" @click.native="onBannerRemove(index)"></a-icon>
      </div>
    </div>
  </div>
</template>

<script>
export default {
    props: {
        banners: {
            type: Array,
            default () {
                return []
            }
        }
    },
    methods: {
        onBannerRemove (index) {
         this.$confirm({
            title: '你确认进行删除操作吗?',
            content: h => <div style="color:red;">删除后将无法进行撤销</div>,
            okType: 'danger',
            onOk: () => Promise.resolve(this.banners.splice(index, 1))
        })
    }
    }
}
</script>

<style lang="less" scoped>
.banners{
  display: flex;
  flex-wrap: wrap;
  .banner{
    margin-bottom: 8px;
    margin-right: 8px;
    width: 116px;
    height: 60px;
    position: relative;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    img{
      width: 100%;
      height: 100%;
      object-fit: cover;
      object-position: center;
    }
    .banner-mask{
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      right: 0;
      background: rgba(0,0,0,0.25);
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s;
      visibility: hidden;
      opacity: 0;
      i{
        margin: 0 8px;
        color: white;
        font-size: 20px;
        &:hover{
          color: #ddd;
        }
      }
    }
    &:hover .banner-mask{
      visibility: visible;
      opacity: 1;
    }
  }
}
</style>>
